home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / dpp / arglist.d < prev    next >
Text File  |  1996-02-04  |  2KB  |  119 lines

  1.  
  2.  
  3.  
  4. /*                                      
  5.  *
  6.  *      Copyright (c) 1994-1996 Algorithms Corporation
  7.  *      3020 Liberty Hills Drive
  8.  *      Franklin, TN 37067
  9.  *
  10.  *      ALL RIGHTS RESERVED.
  11.  *
  12.  *      
  13.  *      
  14.  */
  15.  
  16.  
  17. #include "dpp.h"
  18.  
  19. defclass  ArgumentList : LinkObject;
  20.  
  21. static    void    process_file(object, char *);
  22.  
  23. cmeth    gNew()
  24. {
  25.     return gShouldNotImplement(self, "gNew");
  26. }
  27.  
  28. cmeth    gNewArglist(int argc, char **argv)
  29. {
  30.     int    i;
  31.     object    obj = gNew(super);
  32.     for (i=0 ; i < argc ; i++)
  33.         if (argv[i][0] == '@')
  34.             process_file(obj, 1+argv[i]);
  35.         else
  36.             gAddLast(obj, gNewWithStr(String, argv[i]));
  37.     return obj;
  38. }
  39.  
  40. static    void    process_word(char *word, object list, int noexpand)
  41. {
  42.     int    wild=0;
  43.     char    *w;
  44.  
  45.     if (!noexpand)
  46.         for (w=word ; *w ; w++)
  47.             if (*w == '*'  ||  *w == '?')  {
  48.                 wild = 1;
  49.                 break;
  50.             }
  51.     if (!wild)  {
  52.         gAddLast(list, gNewWithStr(String, word));
  53.         return;
  54.     }
  55.     
  56.     /*  process wild some day...   */
  57.  
  58.     gAddLast(list, gNewWithStr(String, word));
  59. }
  60.  
  61.  
  62. #define space(x)     ((x) <= ' ')
  63.  
  64. static    char    *process_token(char *p, object list)
  65. {
  66.     char    word[128], *w;
  67.     int    inquote, noexpand;
  68.  
  69.     while (*p  &&  space(*p))
  70.         p++;
  71.     if (noexpand = inquote = *p == '"')
  72.         p++;
  73.     for (w=word ; *p  &&  (!space(*p) || inquote) ; p++)
  74.         if (inquote  &&  *p == '"')
  75.             inquote = 0;
  76.         else
  77.             *w++ = *p;
  78.     *w = '\0';
  79.     if (*word == '@')
  80.         process_file(list, word+1);
  81.     else if (*word)
  82.         process_word(word, list, noexpand);
  83.     return p;
  84. }
  85.  
  86. static    void    process_file(object list, char *file)
  87. {
  88.     char    buf[256], *p;
  89.     object    fobj;
  90.  
  91.     fobj = gOpenFile(File, file, "r");
  92.     if (!fobj)  {
  93.         vPrintf(stdoutStream, "Can't open %s\n", file);
  94.         exit(1);
  95.     }
  96.     while (gGets(fobj, buf, sizeof buf))
  97.         for (p=buf ; *(p=process_token(p, list)) ; );
  98.     gDispose(fobj);
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105. /*                                      
  106.  *
  107.  *      Copyright (c) 1994-1996 Algorithms Corporation
  108.  *      3020 Liberty Hills Drive
  109.  *      Franklin, TN 37067
  110.  *
  111.  *      ALL RIGHTS RESERVED.
  112.  *
  113.  *      
  114.  *      
  115.  */
  116.  
  117.  
  118.  
  119.